<template>
  <div>
    <el-alert
      v-if="adminLevel < levelRequirementView"
      title="(⊙o⊙)…您的权限不能访问此页面"
      type="warning"
      :closable="false"
    ></el-alert>
    <div
      v-if="
        adminLevel >= levelRequirementView &&
        fullData &&
        currentData &&
        staffList
      "
      style="padding-top: 60px"
    >
      <nameSelectView
        @do="setPersonID"
        :initValue="currentData.basicData.clientName"
      ></nameSelectView>
      <transition name="el-fade-in">
        <personalView
          v-show="showPersonalView"
          :adminType="adminType"
          :personID="personID"
        ></personalView>
      </transition>
    </div>
  </div>
</template>

<script>
import nameSelectView from "./nameSelectView.vue";
import personalView from "@/views/personalView";
export default {
  name: "modifyView",
  components: {
    nameSelectView,
    personalView,
  },
  data() {
    return {
      levelRequirementEdit: 2,
      levelRequirementView: 1,
      personID: 0,
      showPersonalView: true,
    };
  },
  computed: {
    adminLevel() {
      return this.$store.getters.adminLevel;
    },
    adminType() {
      if (this.adminLevel >= this.levelRequirementEdit) return 2;
      else if (this.adminLevel >= this.levelRequirementView) return 1;
      else return 0;
    },
    staffList() {
      if (this.adminLevel < this.levelRequirementView) return [];
      return this.$store.state.staffList;
    },
    nameList() {
      if (this.adminLevel < this.levelRequirementView) return [];
      return this.$store.state.nameList;
    },
    dataList() {
      if (this.adminLevel < this.levelRequirementView) return [];
      let dataConfig = this.$store.state.dataConfig;
      if (!dataConfig) return null;
      let dataList = new Array();
      for (let i = 0; i < dataConfig.length; i++) {
        if (!dataConfig[i].is_basic) dataList.push(dataConfig[i]);
      }
      return dataList;
    },
    itemList() {
      if (this.adminLevel < this.levelRequirementView) return [];
      let dataConfig = this.$store.state.dataConfig;
      if (!dataConfig) return null;
      let itemList = new Array();
      for (let i = 0; i < dataConfig.length; i++) {
        if (!dataConfig[i].is_basic) itemList.push(dataConfig[i].title);
      }
      return itemList;
    },
    fullData() {
      if (this.adminLevel < this.levelRequirementView) return [];
      return this.$store.state.fullData;
    },
    currentData() {
      if (this.adminLevel < this.levelRequirementView) return [];
      if (!this.fullData) return null;
      return this.fullData[this.personID];
    },
  },
  methods: {
    setPersonID(name) {
      this.showPersonalView = false;
      for (let i = 0; i < this.fullData.length; i++) {
        if (this.fullData[i].basicData.clientName == name) {
          this.personID = i;
          let that = this;
          setTimeout(() => {
            that.showPersonalView = true;
          }, 300);
          return null;
        }
      }
    },
  },
  mounted() {
    if (this.adminLevel >= this.levelRequirementView) {
      if (!this.$store.state.staffList) this.$store.dispatch("getStaffList");
      if (!this.$store.state.fullData) this.$store.dispatch("getFullData");
    }
    // window.console.log("mount");
  },
};
</script>

<style scoped>
</style>